﻿using System;
using System.Collections.Generic;
using KKCai.TC.App.Core;

namespace KKCai.TC.App.DAL
{
    internal class DayCountDao
    {
        public IList<int> List()
        {
            return SessionManager.Instance.GetSession()
                .CreateQuery("select c.Value from DayCountInfo c").List<int>();
        }

        public int Update(string result)
        {
            string[] array = result.Split(',');
            int first = Convert.ToInt32(array[0]) + 11;
            
            string hql = String.Format("update DayCount set Value = Value + 1 where ID in ( {0},{1} )", result, first);

            return SessionManager.Instance.GetSession()
                .CreateSQLQuery(hql)
                .ExecuteUpdate();
        }

        public int Reset()
        {
            return SessionManager.Instance.GetSession()
                .CreateSQLQuery("update DayCount set Value = 0")
                .ExecuteUpdate();
        }
    }
}
